<template>
	<view class="select-space-main">
		<treeRevision :children="dataList" :typeData="typeData"></treeRevision>
	</view>
</template>

<script>
	import {
	  request
	} from "../../request/index.js";
	import treeRevision from "../components/tree-revision/tree-revision.vue"

	export default {
		components: {
			treeRevision,
		},
		data() {
			return {
				dataList: [],
				typeData:""
			};
		},
		mounted() {
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			this.typeData = routes[routes.length - 1 ].options.type // 获取当前页面路由，也就是最后一个打开的页面路由
			if(this.typeData=="business"){
				this.getListBusiness()
			}
			else if(this.typeData=="space"){
				this.getListSpace()
			}
			
		},
		methods: {
			async getListSpace() {
				// 获取空间数据
				let res = await request({
					url: "api/oct/wemini/bus/workOrder/findSpaceList",
					method: "POST",
					data: {
						likeCode: "",
						codeLevel: 1,
						projectId: uni.getStorageSync("projectId") || "16154516457903604960000255341083"
					}
				})
				if (res.status == 0) {
					let list = res.payload
					list.forEach(item => {
						item.joint = item.name
					})

					this.dataList = list
				}
			},
			async getListBusiness() {
				// 获取业务数据
				let res = await request({
					url: "api/oct/wemini/bus/workOrder/findDataCategoryList",
					method: "POST",
					data: {
						categoryCodeLevel: 1,
						likeCategoryCode: "",
					}
				})
				if (res.status == 0) {
					let list = res.payload
					list.forEach(item => {
						item.joint = item.name
						item.spread = false
					})

					this.dataList = list
				}else{
					uni.showToast({
						title: "获取失败!",
						icon: 'none',
						duration: 1000,
						success: (res) => {
					
						},
					})
				}
			}
		}
	}
</script>

<style lang="less">
	.select-space-main {
		background-color: #f2f6ff;
	}
</style>